package com.dykj.fireFighting.web.controller;

import java.util.*;

import com.dykj.fireFighting.api.base.enterprise.entity.Enterprise;
import com.dykj.fireFighting.api.base.enterprise.service.IEnterpriseService;
import com.dykj.fireFighting.api.monitoringCenter.entity.YjInfo;
import com.dykj.fireFighting.api.monitoringCenter.service.IYjInfoService;
import com.dykj.fireFighting.common.core.annotation.AutoLog;
import com.dykj.fireFighting.common.core.api.CommonResult;
import com.dykj.fireFighting.common.core.dto.CommonDto;
import com.dykj.fireFighting.common.core.vo.PageVo;
import com.dykj.fireFighting.web.base.shiro.ShiroUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import javax.validation.Valid;



/**
 * VIEW接口
 *
 * @Author JacksonTu
 * @Date  2021-08-18 08:54:38
 */
@Slf4j
@Api(value = "VIEW接口", tags = {"VIEW接口"})
@RestController
@RequestMapping("yjInfo")
public class YjInfoController {

    @DubboReference
    private IYjInfoService yjInfoService;
    @DubboReference
    private IEnterpriseService enterpriseService;

    /**
     * VIEW列表
     *
     * @return
     */
    @AutoLog(value = "VIEW-分页列表查询")
    @ApiOperation(value = "VIEW分页列表", notes = "VIEW分页列表")
    @GetMapping("/list")
    /*@RequiresPermissions("sms/yjInfo/list")*/
    public CommonResult<PageVo<YjInfo>> treeGrid(CommonDto commonDto) {
        PageVo<YjInfo> page = yjInfoService.pageList(commonDto);
        return CommonResult.success(page);
    }

    /**
     * 获取VIEW信息
     */
    @AutoLog(value = "VIEW-获取VIEW信息")
    @ApiOperation(value = "获取VIEW信息", notes = "获取VIEW信息")
    @ApiImplicitParam(paramType = "path", name = "id", value = "主键ID", dataType = "Long", required = true)
    @GetMapping("/info/{id}")
    /*@RequiresPermissions("sms/yjInfo/info")*/
    public CommonResult<YjInfo> info(@PathVariable("id") Long id){
        YjInfo yjInfo = yjInfoService.getById(id);
        return CommonResult.success(yjInfo);
    }
    @GetMapping("/getYjList")
    public CommonResult<List<YjInfo>>getYjList(){
        Long enterpriseId = ShiroUtil.getUser().getEnterpriseId();
        List<Enterprise> enterprises = enterpriseService.queryUnitSelect(enterpriseId + "");
        List<String> ids=new ArrayList<>();
        for (Enterprise e: enterprises) {
            ids.add(e.getId()+"");
        }
        List<YjInfo> yjList = yjInfoService.getYjList(ids);
        return CommonResult.success(yjList);
    }

}
